<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Catalog</title>
</head>
<body>
<body background="../../img/bg.jpg"> 
	<font face="Berlin Sans FB Demi" color="#357EC7" size="3">
<center>
	<?
include('../auth.php');
include('../../config.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {die('Failed to connect to server: ' . mysql_error());}
           
$db = mysql_select_db(DB_DATABASE);
if(!$db) {die("Unable to select database");}
error_reporting (E_ALL ^ E_NOTICE);
?>
<br><br>
<h1>Adaugare profesor</h2>
<form action="profadd.php" method="post">
<table border="1">
<tr><td>Nume: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="nume"></tr></td>
<tr><td>Diriginte la clasa: <input type="text" name="dirig"></tr></td>
<tr><td>Email: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="email"></tr></td>
<tr><td><center><input type="submit" value="Adauga"></center></tr></td>
</table>
</form>
<?
function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}
$nume=clean($_POST['nume']);
$dirig=clean($_POST['dirig']);
$email=clean($_POST['email']);	
function createRandomPassword() {
$chars = "abcdefghijkmnopqrstuvwxyz023456789!@#$%^&*()_+";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;

}
    return $pass;
}
$password=createRandomPassword();
$mdpas=md5($password);
if ($nume!='' and $dirig!='' and $email!='') {
echo $nume;
echo $mdpass;

$sql64=mysql_query("insert into profesori(nume,parola,dirig,email) values ('".$nume."','".$mdpas."','".$dirig."','".$email."')");
$admin=$_SESSION['SESS_PROFNAME'];
mail($email,'Subject: Parola catalog online',"Parola catalog online: $password <br> Ati fost adaugat ca profesor de $admin",'From: Catalog online');
echo '<script type="text/javascript">
window.location = "prof.php"
</script>';
}
?>
</font>
</body>
</html>